//
//  LJJViewChainable.swift
//  DYDemo
//
//  Created by liujunjie on 2018/10/31.
//  Copyright © 2018 liujunjie. All rights reserved.
//

/*
 链式编程-根
 */
import UIKit

public protocol LJJViewChainable {}

public extension LJJViewChainable where Self: UIView {
    
    /**
     控件属性配置
     */
    @discardableResult
    public func ljj_config(_ config:(Self)->Void) -> Self {
        config(self)
        return self
    }
    
    /**
     控件布局配置
     警告:调用此方法时,如用到Masory控件,q需要先添加View(addSubView),后调用此方法
     */
    @discardableResult
    public func ljj_layout(_ layout:(Self)->Void) -> Self {
        layout(self)
        return self
    }
    
}

extension UIView: LJJViewChainable {
    
    /**
     添加到父视图
     */
    @discardableResult
    public func ljj_addToView(_ superView: UIView) -> Self {
        superView.addSubview(self)
        return self
    }
    
    /**
     View,frame 设置
     */
    @discardableResult
    public func ljj_addCGRect(_ cgrect: CGRect) -> Self {
        self.frame = cgrect
        return self
    }
}
